<?php

require_once 'common/conn.php';
require_once 'common/common.php';

$data = array();

if (isset($_GET['usercode']) && isset($_GET['code'])) {
    $usercode = trim($_GET['usercode']);
    $code = trim($_GET['code']);
    $db = new DBC();
    $sql = "SELECT id FROM t_hibaby_title_download WHERE usercode = '" . $usercode . "' AND code = '" . $code . "'";
    if (!checkArrayNotEmpty($db->fetchData($sql))) {
        $sql = "INSERT INTO t_hibaby_title_download(code,usercode,createTime) VALUES('" . $code . "','" . $usercode . "',now())";
        if ($db->execute($sql)) {
            $data['errorNo'] = "0";
            $data['errorMsg'] = "";
        } else {
            $data['errorNo'] = "1";
            $data['errorMsg'] = "下载失败";
        }
    } else {
        $data['errorNo'] = "3";
        $data['errorMsg'] = "已下载";
    }
}
echo json_encode($data);
?>